package com.hctg.forced2sleep.adapter;

import com.blankj.utilcode.util.AppUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hctg.forced2sleep.R;

import java.util.ArrayList;

public class AppChooseAdapter extends BaseQuickAdapter<AppUtils.AppInfo, BaseViewHolder> {
//    public ExecutorService A;
    public ArrayList<String> packageNames = new ArrayList<>();
    public boolean isSelectAble;

    /**
     * @param isSelectAble 是否能选中
     */
    public AppChooseAdapter(boolean isSelectAble) {
        super(R.layout.item_app_choose);
//        this.A = Executors.newSingleThreadExecutor();
        this.isSelectAble = isSelectAble;
    }

    @Override
    public void convert(BaseViewHolder holder, AppUtils.AppInfo item) {
        holder.setImageDrawable(R.id.iv_icon, item.getIcon())
                .setText(R.id.tv_app_name, item.getName());
        if (isSelectAble) {
            holder.getView(R.id.item).setSelected(packageNames.contains(item.getPackageName()));
        } else {
            holder.setVisible(R.id.iv_open, false);
        }
    }
}
